package fule.com.playandroidkotlin.ui.presenter

import fule.com.playandroidkotlin.base.BaseListModel
import fule.com.playandroidkotlin.base.BaseModel
import fule.com.playandroidkotlin.base.BaseObserver
import fule.com.playandroidkotlin.base.BasePresenter
import fule.com.playandroidkotlin.ui.model.ProjectListModel
import fule.com.playandroidkotlin.ui.model.ProjectTitleModel
import fule.com.playandroidkotlin.ui.view.ProjectView

/**
 * 作者： njb
 * 时间： 2018/8/10 0010-上午 10:31
 * 描述： 项目
 * 来源：
 */
class ProjectPresenter(baseView: ProjectView) : BasePresenter<ProjectView>(baseView) {

    /**
     * 项目分类标题
     */
    fun projectTree() {
        addDisposable(apiServer.projectTree(), object : BaseObserver<BaseListModel<ProjectTitleModel.DataBean>>(baseView) {
            override fun onSuccess(o: BaseListModel<ProjectTitleModel.DataBean>) {
                baseView.onLoadProjectTree(o.data!!)
            }

            override fun onError(msg: String?) {
                baseView.showError(msg!!)
            }

        })
    }

    /**
     * 项目分类列表
     */
    fun projectList(cid: Int, page: Int) {
        addDisposable(apiServer.projectList(cid, page), object : BaseObserver<BaseModel<ProjectListModel>>(baseView) {
            override fun onSuccess(o: BaseModel<ProjectListModel>) {
                baseView.onLoadProjectList(o.data!!)
            }

            override fun onError(msg: String?) {
                baseView.showError(msg!!)
            }
        })
    }
}
